package com.tdkj.action.front.yellowpage;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;

import com.tdkj.action.BaseAction;
import com.tdkj.model.friendlylink.BeanFriendlylink;
import com.tdkj.model.yellowpage.BeanEnterprice;
import com.tdkj.service.yellowpage.IBeanEnterpriceService;
public class EnterpriceAction  extends BaseAction{
	private long id;
	private BeanEnterprice enterprice=new BeanEnterprice();;
	private IBeanEnterpriceService enterpriceService;
	private List<BeanEnterprice> enterprices=new ArrayList<BeanEnterprice>();
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	public List<BeanEnterprice> getEnterprices() {
		return enterprices;
	}
	public void setEnterprices(List<BeanEnterprice> enterprices) {
		this.enterprices = enterprices;
	}
	public BeanEnterprice getEnterprice() {
		return enterprice;
	}
	public void setEnterprice(BeanEnterprice enterprice) {
		this.enterprice = enterprice;
	}
	public IBeanEnterpriceService getEnterpriceService() {
		return enterpriceService;
	}
	@Resource
	public void setEnterpriceService(IBeanEnterpriceService enterpriceService) {
		this.enterpriceService = enterpriceService;
	}
	//
	public String findAll(){
		appendObj(20);
		enterprices=enterpriceService.findAll(BeanEnterprice.class);
		return "findAll";
	}
	public String findList(){
		Criteria criteria = this.createCriteria(BeanEnterprice.class);
		criteria.addOrder(Order.desc("createtime"));// 对状态进行排序
		this.queryByPage(criteria, "enterpriceAction!findList.action", 10);
		return "list";
	}
	public String findContent(){
		enterprice=enterpriceService.findById(this.getId(), BeanEnterprice.class);
		return "content";
	}
	private  void appendObj(int num) {
		// TODO Auto-generated method stub
		BeanEnterprice bean=null;
		for(int i=0;i<num;i++){
			bean=new BeanEnterprice();
			bean.setAddress("昆明");
			bean.setCreatetime(new Timestamp(System.currentTimeMillis()));
			bean.setEnterpricename("中国之最科技有限公司");
			enterpriceService.save(bean);
		}
	}
}
